{template 'common/header'}

<div class="main">
	<ul class="nav nav-tabs">
	  <li {if $op == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('activity',array('op'=>'display'));}">活动列表</a></li>
	  <li {if $op == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('activity', array('op' => 'post'));}">添加活动</a></li>
	</ul>
{if $op =='display'}
		<form id="form2" class="form-horizontal" method="post">
			<table class="table table-hover">
				<thead class="navbar-inner">
					<tr>
						<th style="width:40px;">全选</th>
	          			<th style="width:200px;">活动名称</th>
	          			<th style="width:300px;">地址</th>
	          			<th style="width:100px;">状态</th>
						<th style="width:80px;">操作</th>
					</tr>
				</thead>
				<tbody>
					{loop $list $item}
					<tr>
						<td><input type="checkbox" value="{$item['id']}" name="delete[]"></td>
						<td>{$item['title']}</td>
						<td><input type="text" class="form-control" value="{php echo self::str_murl($this->createMobileUrl('lottery', array('id' => $item['id'])))}" /></td>
						<td>
							{if $item['status']==1}
							<span class="label label-success">启用</span>
							{else}
							<span class="label label-default">停用</span>
							{/if}
						</td>
						<td>
						<!-- <a href="{php echo $this->createWebUrl('joinLog',array('id'=>$item['id']));}" class="btn btn-xs btn-info"><span class="icon icon-compose">中奖纪录</span></a> -->
						<a href="{php echo $this->createWebUrl('activity', array('op' => 'post', 'id' => $item['id']))}" title="编辑" class="btn btn-xs btn-primary"><span class="icon icon-compose">编辑</span></a>
						<a onclick="if(confirm('此操作不可恢复，确认吗？')){location.href='{php echo $this->createWebUrl('activity', array('id' => $item['id'],'op'=>'del'))}'}" href="javascript:;" title="删除" class="btn btn-xs btn-danger"><span class="icon icon-close">删除</span></a>
						</td>				
					</tr>
					{/loop}
					<tr >
						<td colspan="2"><input type="checkbox"  onclick="var ck = this.checked;$(':checkbox').each(function(){this.checked = ck});" name=''>
							<input class="btn btn-primary btn-xs" type="submit" value="删除" name="submit" >
						</td>
						<td></td><td></td><td></td>
					</tr>
				</tbody>
			</table>
			<input type="hidden" value="activity" name="do">
			<input type="hidden" value="del" name="op">
			<input type="hidden" name="token" value="{$_W['token']}" />
		</form>
		{$pager}
		
		<script>
			$('#form2').submit(function(){
				if($(":checkbox[name='delete[]']:checked").size() > 0){
					return confirm('删除后不可恢复，您确定删除吗？');
				}
				return false;
			}); 
		</script>	
	</div>
{elseif $op == 'post'}
	<ul class="nav nav-tabs nav-justified" role="tablist">
	<li {if $_GPC['step']==1 || $_GPC['step']==''}class="active"{/if} role="presentation">
		<a href="javascript:;">1. 活动基本信息</a>
	</li>
	<li {if $_GPC['step']==2}class="active"{/if} role="presentation">
		<a href="javascript:;">2. 奖项设置</a>
	</li>
	<li {if $_GPC['step']==3}class="active"{/if} role="presentation">
		<a href="javascript:;">3. 完成</a>
	</li>
	</ul>
	<div class="main">
	{if $_GPC['step'] == 1 || $_GPC['step'] == ''}
		<form action="" method="post" class="form-horizontal form">
			<input type="hidden" name="step" value="2">
			<div class="panel panel-default">	
				<div class="panel-body">
					<div class="form-group hide">
						<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">活动状态</label>
						<div class="col-sm-8">
							<input name="status" type="radio" value="0" {if $item['status']=="0"} checked="checked" {/if} /> 停用&nbsp;&nbsp;&nbsp;&nbsp;
							<input name="status" type="radio" value="1" {if $item['status']=="1"} checked="checked" {/if} /> 启用
							<span class="help-block"></span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">抽奖人数</label>
						<div class="col-sm-8">
							<input type="text" name="num" class="form-control" value="{$item['num']}" />
							<span class="help-block">如输入100，抽奖编号则为1-100，以此类推</span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">活动标题</label>
						<div class="col-sm-8">
							<input type="text" name="title" class="form-control" value="{$item['title']}" />
							<span class="help-block"></span>
						</div>
					</div>	
					<div class="form-group">
						<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">活动logo</label>
						<div class="col-sm-8">
							{php echo tpl_form_field_image('logo',$item['logo']);}
							<span class="help-block"></span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">活动背景图</label>
						<div class="col-sm-8">
							{php echo tpl_form_field_image('backdrop',$item['backdrop']);}
							<span class="help-block">不填，则显示默认图片</span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">活动发起方</label>
						<div class="col-sm-8">
							<input type="text" name="originator" class="form-control" value="{$item['originator']}" />
							<span class="help-block">显示页面底部</span>
						</div>
					</div>
					
				</div>
			</div>
			
					<div class="form-group">
						<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>
						<div class="col-sm-4">
							<input type="hidden" name="id" value="{$item[id]}">
							<input type="hidden" name="token" value="{$_W['token']}" />
							<input name="submit" type="submit" value="下一步" class="btn btn-primary span3" />
						</div>
					</div>
		</form>
	{elseif $_GPC['step']== 2}
	<form action="" method="post"  class="form-horizontal" role="form" enctype="multipart/form-data" id="form1">
	<input type="hidden" name="step" value="3">
	<table class="table table-hover">
		<thead>
		<tr>
			<th style='width:5%;'>ID</th>
			<th style='width:5%;'>排序</th>
			<th style='width:40%;text-align:center;'>等级</th>
			<th style='width:40%;text-align:left;'>名额</th>
			<th style='width:10%;'>操作</th>
		</tr>
		</thead>
		<tbody id="param-items">
			{loop $items $p}
			{php $levelname=array('1'=>'一等奖','2'=>'二等奖','3'=>'三等奖','4'=>'四等奖','5'=>'五等奖');}
			<tr>
				<td>{$p['id']}</td>
				<td><input type="text" class="form-control" name="displayorder[{$p['id']}]" value="{$p['displayorder']}"></td>
				<td style='text-align:center;'>{php echo $levelname[$p['level']]}</td>
				<td style='text-align:left;'>{if $p['limit_num'] != 0}{$p['limit_num']}个{else}不限制{/if}</td>
				<td><a href="{php echo $this->createWebUrl('activity',array('id'=>$id,'op'=>'post','step'=>'2','item_id' => $p['id']))}">修改</a> | 
					<a href="{php echo $this->createWebUrl('activity',array('id'=>$id,'op'=>'itemdelete','item_id' => $p['id']))}">删除</a></td>
			</tr>
			{/loop}
			<tr>
                <td colspan="8">
                    <input name="display" type="submit" class="btn btn-primary" value="批量更新排序">
                    <input type="hidden" name="token" value="{$_W['token']}" />
                </td>
            </tr>
		</tbody>
	</table>
	</form>
	<form action="" method="post"  class="form-horizontal" role="form" enctype="multipart/form-data" id="form2">
		<input type="hidden" name="step" value="3">
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
			<div class="col-sm-2 col-xs-2">
				<input type="text" name="displayorder" id="displayorder" class="form-control" value="{if !empty($item_info)}{$item_info['displayorder']}{else}0{/if}" />
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>中奖等级</label>
			<div class="col-sm-2 col-xs-2">
					<select name="level" id="level" class="form-control" />
						<option  value="1" {if $item_info['level']=='1'}selected{/if}>一等奖</option>
						<option  value="2" {if $item_info['level']=='2'}selected{/if}>二等奖</option>
						<option  value="3" {if $item_info['level']=='3'}selected{/if}>三等奖</option>
						<option  value="4" {if $item_info['level']=='4'}selected{/if}>四等奖</option>
						<option  value="5" {if $item_info['level']=='3'}selected{/if}>五等奖</option>
					</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>限定名额</label>
			<div class="col-sm-2 col-xs-2">
				<div class="input-group">
					<input type="text" name="limit_num" id="limit_num" class="form-control" value="{$item_info['limit_num']}" />
					<span class="input-group-addon">个</span>
				</div>
				<span class="help-block"></span>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-12">
				<a href="{php echo $this->createWebUrl('activity',array('id'=>$id,'op'=>'post','step'=>'1'))}" class="btn btn-default">上一步</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input name="submit" type="submit" value="保存" class="btn btn-primary" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a href="{php echo $this->createWebUrl('activity',array('id'=>$id,'op'=>'post','step'=>'3'))}" class="btn btn-default">下一步</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</div>
	</form>
	<script type="text/javascript">
	require(['jquery', 'util'], function($, u){
		$("#form2").submit(function(){
			if($(":text[name='limit_num']").val() == '') {
				u.message('抱歉，支持金额为必填项！', '', 'error');
				return false;
			}
			return true;
		});
	});
	</script>
	{elseif $_GPC['step']==3}
	<form action="" method="post"  class="form-horizontal" role="form" enctype="multipart/form-data" id="form2">
		<input type="hidden" name="step" value="4">
		<h3 style="margin-bottom:20px;">^_^恭喜您，只需最后一步您就可以开始现场抽奖！</h3>
		<div class="form-group">
			<div class="col-sm-12">
			<form action="" method="post"  class="form-horizontal" role="form" enctype="multipart/form-data" id="form3">
				<a href="{php echo $this->createWebUrl('activity',array('id'=>$id,'op'=>'post','step'=>'2'))}" class="btn btn-default">上一步</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input name="save" type="submit" value="保存为草稿" class="btn btn-primary" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input name="finish" type="submit" value="完成" class="btn btn-success" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="hidden" name="token" value="{$_W['token']}" />
			</form>
			</div>
		</div>
	</form>
	{/if}
	</div>
{/if}		
</div>

{template 'common/footer'}
